/**
 * @class   wosh::gui::DialogCreateGui
 * @brief   
 *          
 *          
 *
 ****************************************************************************
 * @version $Id: DialogCreateGui.h 2488 2010-05-21 01:48:27Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Gui_DialogCreateGui_H__
 #define __WOSH_Gui_DialogCreateGui_H__

 #include <framework/gui/IWidget.h>
 #include <QtGui/QDialog>
 #include <framework/gui/widgets/wCore_Object.h>

 #include "ui_DialogCreateGui.h"

 #include <core/Request.h>
 #include <core/Response.h>
 #include <core/List.h>
 #include <core/InterfacesProvider.h>
 #include <core/MethodsCommon.h>
 #include <core/List.h>
 #include <core/URI.h>


namespace wosh {
 namespace gui {


class DialogCreateGui :	public QDialog,
						public IWidget
 {
	Q_OBJECT

	WOSH_CLASSNAME(wosh::gui::DialogCreateGui)
	WOSH_CLASS_ABSTRACT(false)

	public:
		enum DIALOG_MODE {
			DIALOG_REMOTE_OBJECT = 0,
			DIALOG_LOCAL_OBJECT = 1,
			DIALOG_MIXED = 2
		 };

	public:
		DialogCreateGui( QWidget *parent = NULL );
		virtual ~DialogCreateGui();

		QWidget* asQWidget()				{ return this; }



	public:
		void setMode( DIALOG_MODE mode );

		void configureForObjectType( const char* class_name, double version = 0.0, bool update_combo = false );
		void setupForLocalObject( ISerializable* obj );
		void setupForLocalObject( const ISerializable* obj );

		void setTargetURI( const URI& uri );


	public:
		ISerializable* getSerializableObject()		{ return this->sand_obj; }


	public slots:
		void refreshAll();

		void refreshObjectTypeList();

		void doReset();
		void doAutoDetect();


		void cmbSandObjectType_currentIndexChanged( int index );
		void btnSandObjectAllocate_clicked();
		void btnSandObjectDestroy_clicked();


	public:
		void busMessage( const Message& message, const Bus* );




	protected slots:
		void changedURI( const URI& uri );

	protected:
		void changeEvent(QEvent *e);


	protected:
		ObjectTypeInfoListModel* serializable_types_model;
		ISerializable* sand_obj;
		ObjectTypeInfoTableModel* gui_types_model;


	private:
		Ui::DialogCreateGui *m_ui;


//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------


	public:
		std::string& getName()				{ return this->itemName; }
		std::string& getType()				{ return this->itemType; }
//		URI& getURI()						{ return this->itemURI; }
		QStringList& getInterfaces()		{ return this->itemInterfaces; }
/*
		void setTypes( const std::vector<std::string>& types ) {
			this->m_ui->cmbType->clear();
			this->m_ui->cmbType->setEditText("");

			std::vector<std::string>::const_iterator it;
			for(it=types.begin(); it!=types.end(); it++) {
				this->m_ui->cmbType->addItem( (*it).c_str() );
			 }
		 }
*/


		void txtType_editTextChanged( const QString& text ) {
			this->itemType.assign( text.toLatin1().data() );
		 }

	protected:
		void buildInterfacesList();

	protected:
		std::string itemName;
		std::string itemType;
		QStringList itemInterfaces;

}; // class def

 }; // namespace gui
}; // namespace wosh


#endif // __WOSH_Gui_DialogCreateGui_H__
